package com.tbit.api;

import com.tbit.common.entity.view.Result;
import com.tbit.manager.api.StudentAuthApplyApi;
import com.tbit.manager.api.dto.StudentAuthApplyDTO;
import com.tbit.uqbike.object.pojo.StudentAuthApply;
import com.tbit.uqbike.object.value.LoginInfo;
import com.tbit.uqbike.service.business.StudentAuthApplyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

/**
 * 运维端学生认证实现
 *
 * @since 2024/11/28
 */
@RestController
@Slf4j
public class StudentAuthApplyApiImpl implements StudentAuthApplyApi {

    @Autowired
    private StudentAuthApplyService studentAuthApplyService;

    @Override
    public void editStudentAuth(StudentAuthApplyDTO studentAuthApplyDTO) {
        if (studentAuthApplyDTO.getAgree() == null) {
            studentAuthApplyDTO.setAgree(0);
        }

        LoginInfo loginInfo = new LoginInfo();
        loginInfo.setType(studentAuthApplyDTO.getLoginUserType());
        loginInfo.setId(studentAuthApplyDTO.getLoginUserAccountId());

        studentAuthApplyService.edit(loginInfo, studentAuthApplyDTO.getApplyId(), studentAuthApplyDTO.getCheckOpinion(),
                studentAuthApplyDTO.getAgree(), studentAuthApplyDTO.getStudentNO());

    }

    @Override
    public StudentAuthApplyDTO getStudentApplyById(Integer userId) {
        StudentAuthApplyDTO studentAuthApplyDTO = new StudentAuthApplyDTO();
        Result<StudentAuthApply> result = studentAuthApplyService.getStudentApplyById(userId);
        StudentAuthApply studentAuthApply = result.getData();
        BeanUtils.copyProperties(studentAuthApply, studentAuthApplyDTO);
        return studentAuthApplyDTO;
    }

    @Override
    public void clearAuth(Integer userId) {
        studentAuthApplyService.clearAuthInfo(userId);
    }
}
